# _*_ encoding:utf-8 _*_
# 效果不稳定，选择使用脚本转码

import os
import json
import time
from progressbar import *


def getM4A():
    mp3_path = ""
    with open("./config.json", 'rb') as f:
        config = json.load(f)
        mp3_path = config['mp3_path']
    # mp3文件所在文件夹
    mp3_file = os.listdir(mp3_path)
    print('转码开始')

    progress = ProgressBar()
    for name in progress(mp3_file):
        try:
            index = name.rfind('.')
            name = name[:index]
            os.system("ffmpeg -i " + mp3_path + name
                      + ".mp3 " + mp3_path + name + ".m4a -loglevel quiet")
            time.sleep(1)
        except:
            print("\033[1;31m 转码失败！\033[0m")
    print('转码结束')
